package com.zm.demo.core.leetcode;

import java.util.Stack;

public class MyQueue {

    Stack<Integer>stack1 = new Stack<>();
    Stack<Integer>stack2 = new Stack<>();
    int count=0;
    /** Initialize your data structure here. */
    public MyQueue() {

    }
    
    /** Push element x to the back of queue. */
    public void push(int x) {
        stack1.push(x);
        count++;
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {

        for (int i = 0; i < count-1; i++) {
            stack2.push(stack1.pop());
        }
        int r = stack1.pop();
        for (int i = 0; i < count-1; i++) {
            stack1.push(stack2.pop());
        }
        count--;
        return r;
    }

    /** Get the front element. */
    public int peek() {
        for (int i = 0; i < count-1; i++) {
            stack2.push(stack1.pop());
        }
        int r = stack1.peek();
        for (int i = 0; i < count-1; i++) {
            stack1.push(stack2.pop());
        }
        return r;
    }
    
    /** Returns whether the queue is empty. */
    public boolean empty() {
        return count == 0;
    }
}